package cn.doitedu.datagen.beans;


import com.alibaba.fastjson.JSON;
import jdk.nashorn.internal.parser.JSONParser;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.HashSet;

/***
 * @author hunter.d
 * @qq 657270652
 * @wx haitao-duan
 * @date 2021/12/13
 **/
public class GenUsers {

    public static void main(String[] args) throws Exception {

        String[] seps = {"_", " ",",", "."};
        HashSet<String> names = new HashSet<String>();
        for (int i = 0; i < Long.parseLong(args[0]); i++) {
            String name = RandomStringUtils.randomAlphabetic(2, 5).toLowerCase() + seps[RandomUtils.nextInt(0, seps.length)] + RandomStringUtils.randomAlphabetic(2, 5).toLowerCase();
            if(i % 5 == 0){
                name = StaticResources.getChineseName();
            }
            names.add(name);
        }

        BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
        for(String name:names){
            User user = new User();
            user.setAccount(name);
            user.setAppid(StaticResources.getAppId());
            user.setCarrier(StaticResources.getCarrier());
            user.setAppversion(StaticResources.getAppVersion());

            // "MEIZU-ML7,android,9.5,2048*1024"
            String[] phoneInfos = StaticResources.getPhoneInfo().split(",");
            user.setDevicetype(phoneInfos[0]);
            user.setDeviceid(RandomStringUtils.randomAlphabetic(12).toUpperCase());
            user.setOsname(phoneInfos[1]);
            user.setOsversion(phoneInfos[2]);
            user.setResolution(phoneInfos[3]);

            user.setIp(RandomUtils.nextInt(1,200)+"."+RandomUtils.nextInt(0,200)+"."+RandomUtils.nextInt(0,200)+"."+RandomUtils.nextInt(1,200));

            String[] gpsTuple = StaticResources.getGps().split(",");
            user.setLatitude(Double.parseDouble(gpsTuple[0])+RandomUtils.nextDouble(0.00002,0.001));
            user.setLongitude(Double.parseDouble(gpsTuple[1])+RandomUtils.nextDouble(0.00002,0.001));

            user.setNettype(StaticResources.getNetType());

            user.setReleasechannel(StaticResources.getChannel());

            bw.write(JSON.toJSONString(user));
            bw.newLine();
        }

        bw.close();
    }
}
